import { routes } from '@/router/index'

export function genMenuList() {
  // console.log(routes)
  const router = routes.filter(route => route.path === '/')
  if (router.length > 0) {
    const routeList = router[0].children
    const menuList = getMenuData(routeList)
    return menuList
  }
  return []
}

function getMenuData(menus: any[]) {
  const menuList = []
  for (const item of menus) {
    const newItem: any = {
      id: item.name,
      name: item.meta.title || '',
      path: item.path,
      icon: item.meta.icon || ''
    }
    if (item.children && item.children.length > 0) {
      const menuList = getMenuData(item.children)
      newItem.children = menuList
    }
    menuList.push(newItem)
  }
  return menuList
}
